package com.chun.analyzation.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chun.analyzation.mapper.AnalyzeMapper;
import com.chun.analyzation.service.AnalyzeService;
import com.czy.learning.questionnature.mapper.QuestionNatureMapper;
import com.lin.learning.questionmanagement.mapper.QuestionMapper;
import com.lin.learning.questionmanagement.service.QuestionService;
import com.ni.learning.exam.controller.AnswerSheetController;
import com.our.learning.infrastructure.po.*;
import com.our.learning.infrastructure.pojo.Response;
import com.our.learning.infrastructure.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class AnalyzeServiceImpl extends ServiceImpl<AnalyzeMapper, WrongQuestionReport> implements AnalyzeService {

  /*  @Autowired
    private AnalyzeMapper analyzeMapper;

    @Autowired
    private QuestionService questionService;

    @Autowired
    private QuestionMapper questionMapper;

    @Autowired
    private QuestionNatureMapper questionNatureMapper;

    private AnswerSheetController answerSheetController;


    @Override
    public ResponseResult generateWrongReport(Integer stuid, Integer paperid) {
        //通过学生和试卷id找到错题列表
        Response wrongQuestionidList = answerSheetController.getIncorrectIds(stuid,paperid);
        Map<String, Object> data = wrongQuestionidList.getData();
        List<Integer> wrongQuestionIdList = (List<Integer>) data.get("ids");
        //通过错题id找到相应错题
        String questionList="";

        for(int i=0;i<wrongQuestionIdList.size();i++){
            String id=wrongQuestionIdList.get(i).toString();
            if (i<wrongQuestionIdList.size()-1){
                questionList=questionList+id+',';
            }else {
                questionList=questionList+id;
            }


        }
        WrongQuestionReport wrongQuestionReport=new WrongQuestionReport();
        wrongQuestionReport.setWrongIdList(questionList);
        save(wrongQuestionReport);

        //把获取到的数据组成错题报告
        List<Question> questionList1=questionMapper.selectBatchIds(wrongQuestionIdList);
        List<QuestionNature> questionNatureList=questionNatureMapper.selectBatchIds(wrongQuestionIdList);
        List<ReportItem> reportItemList=new ArrayList<>();
        ReportItem reportItem=new ReportItem();
        for(int i=0;i<questionList1.size();i++){
            reportItem.setQuestion(questionList1.get(i));
            reportItem.setAnswer(questionNatureList.get(i).getAnswer());
            reportItem.setDifficulty(questionNatureList.get(i).getDifficulty());
            reportItem.setKnowledge(questionNatureList.get(i).getKnowledge());
            reportItemList.set(i,reportItem);
        }

        return ResponseResult.okResult(reportItemList);
    }

    @Override
    public ResponseResult getWrongReport(Integer stuid, Integer paperid) {
        LambdaQueryWrapper<WrongQuestionReport> lambdaQueryWrapper=new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(WrongQuestionReport::getStudentId,stuid).eq(WrongQuestionReport::getPaperId,paperid);
        WrongQuestionReport report = getOne(lambdaQueryWrapper);
        String wrongQuestionIdList= report.getWrongIdList();
        String[] split = wrongQuestionIdList.split(",");
        List<String> id = Arrays.asList(split);
        //把获取到的数据组成错题报告
        List<Question> questionList1=questionMapper.selectBatchIds(id);
        List<QuestionNature> questionNatureList=questionNatureMapper.selectBatchIds(id);
        List<ReportItem> reportItemList=new ArrayList<>();
        ReportItem reportItem=new ReportItem();
        for(int i=0;i<questionList1.size();i++){
            reportItem.setQuestion(questionList1.get(i));
            reportItem.setAnswer(questionNatureList.get(i).getAnswer());
            reportItem.setDifficulty(questionNatureList.get(i).getDifficulty());
            reportItem.setKnowledge(questionNatureList.get(i).getKnowledge());
            reportItemList.set(i,reportItem);
        }

        return ResponseResult.okResult(reportItemList);
    }*/
}
